#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@文件    :Untitled-3
@说明    :
@时间    :2020/05/10 23:47:08
@作者    :王舰航
@版本    :3.0
'''
# 有100个同学的分数：数据请用随机函数生成；
#      A  利用多线程程序（比如，5个线程，每个线程负责输出20条记录），快速输出这100个同学的信息；
#      B 利用线程池来实现；

import threading, random, time

number = 1
mutex = threading.Lock()

class Score( threading.Thread ):

    def run( self ):
        global number
        for i in range(10):
            mutex.acquire()
            score = random.randint( 0, 100 )
            print( ' score of Student%s is: %s.' %( number, score ) )
            number += 1
            mutex.release()
            time.sleep( 1 )

if __name__ == "__main__":

    t1 = Score()
    t2 = Score()
    t3 = Score()
    t4 = Score()
    t5 = Score()
    t6 = Score()
    t7 = Score()
    t8 = Score()
    t9 = Score()
    t10 = Score()

    t1.start()
    t2.start()
    t3.start()
    t4.start()
    t5.start()
    t6.start()
    t7.start()
    t8.start()
    t9.start()
    t10.start()